package org.hnsd.train.pattern.singleton;


import java.util.Properties;

/**
 * 读取配置文件
 *
 * @author youqd
 * @tag.date 2023-11-01 10:23
 **/
public class ConfigReader {
    private  String userName = null;
    private  String userPass = null;

    private static ConfigReader configReader = null;

    private ConfigReader() {
    }

    public static ConfigReader getInstance() {
        if (null == configReader) {
            configReader = new ConfigReader();
            configReader.readConfig();
        }
        return configReader;
    }

    public void readConfig() {
        try {
            Properties properties = new Properties();
            properties.load(configReader.getClass().getResourceAsStream("/conf.properties"));
            userName = properties.getProperty("userName");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        for(int i = 0;i < 10 ; i++) {
            ConfigReader configReader = ConfigReader.getInstance();
            System.out.println(configReader);
            System.out.println(configReader.userName);
        }
    }
}
